package com.StarStudio.Controller;


import com.ruoyi.common.core.Entity.*;
import com.StarStudio.Service.StatisticalDataService;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.api.domain.SysUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/statistical_data")
@Api(tags = "统计数据接口")
public class StatisticalDataController {

    @Autowired
    StatisticalDataService statisticalDataService;

    @GetMapping
    @ApiOperation("统计数据接口（若是银行用户登录，则展示银行视角数据；若是普通商家用户登录，则展示商家视角数据）")
    public Result getBankStatisticalData(){
        SysUser sysUser = SecurityUtils.getLoginUser().getSysUser();
        if (sysUser.isAdmin()){
            BankStatisticalData bankStatisticalData;
            try {
                bankStatisticalData = statisticalDataService.getBankStatisticalData();
            } catch (Exception e) {
                e.printStackTrace();
                return new Result(HttpStatusCode.ERROR, MessageConstant.GET_BANK_STATISTICAL_DATA_FAIL);
            }
            return new Result(HttpStatusCode.SUCCESS,MessageConstant.GET_BANK_STATISTICAL_DATA_SUCCESS,bankStatisticalData);
        } else {
            StoreStatisticalData storeStatisticalData;
            try {
                storeStatisticalData = statisticalDataService.getStoreStatisticalData();
            } catch (Exception e) {
                e.printStackTrace();
                return new Result(HttpStatusCode.ERROR,MessageConstant.GET_STORE_STATISTICAL_DATA_FAIL);
            }
            return new Result(HttpStatusCode.SUCCESS,MessageConstant.GET_STORE_STATISTICAL_DATA_SUCCESS,storeStatisticalData);
        }
    }
}
